package de.recipeminer.ui.commands.workflow;

import com.db4o.ObjectSet;
import com.google.common.collect.Lists;
import de.recipeminer.environments.ExecutionContext;
import de.recipeminer.environments.ExecutionContextProvider;
import de.recipeminer.models.chefkoch.ChefkochRecipe;
import de.recipeminer.persistence.Db4oContainer;
import joptsimple.OptionSet;
import org.apache.log4j.Logger;

import java.util.ArrayList;
import java.util.Iterator;

/**
 * @autor: Markus Ackermann
 */
public class ExtractionCommand // extends UserCommand.WorkflowCommand
{
    private static Logger logger = Logger.getLogger(ExtractionCommand.class);
    static ArrayList<ChefkochRecipe> list = Lists.newArrayList();

    //@Override
    public boolean run(OptionSet options) {
        //MA: modified to suit new execution context interfaces. Getting a specific context has become
        //quite verbose, as now arbitrary context names are possible.
        ExecutionContext testContext = ExecutionContextProvider.getInstance().getContext(ExecutionContext.Names.TEST);
        Db4oContainer db4 = testContext.getContainer();
        ObjectSet<ChefkochRecipe> res = db4.query(ChefkochRecipe.class);
        Iterator<ChefkochRecipe> it = res.iterator();

        for (int i = 1; i <= 10 && it.hasNext(); i++) {
        list.add(it.next());
        
        }

        return false; //MA: added to make it compile, unsure about proper semantics
                      //  of this return value

    }

    //@Override
    public String commandName() {
        throw new UnsupportedOperationException();
    }
}
